<template>
    <div>
        <div class="header" v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
            element-loading-background="rgba(0, 0, 0, 0.8)">
            <div class="button" style="margin-left: 8%; margin-bottom: 4%;">
                <el-row :gutter="20" class="el-row">
                    <el-col :span="5"><el-button type="success" @click="read">召唤参数</el-button></el-col>
                    <el-col :span="5"><el-button type="success" @click="download">下载参数</el-button></el-col>
                </el-row>
            </div>
            <div class="form">
                <el-form :label-position="labelPosition" :model="formLabelAlign" :inline="true">
                    <el-form-item label="LED屏切屏时间(sec)">
                        <el-input v-model="formLabelAlign.LED"></el-input>
                    </el-form-item>
                    <el-form-item label="TSP偏美值">
                        <el-input v-model="formLabelAlign.TSP"></el-input>
                    </el-form-item>
                    <el-form-item label="扬尘启动值(ug/m3)">
                        <el-input v-model="formLabelAlign.firing"></el-input>
                    </el-form-item>
                    <el-form-item label="扬尘控制回差(ug/m3)">
                        <el-input v-model="formLabelAlign.returndifference"></el-input>
                    </el-form-item>
                    <el-form-item label="雾炮最长工作时间(min)">
                        <el-input v-model="formLabelAlign.Max"></el-input>
                    </el-form-item>
                    <el-form-item label="雾炮最小工作时间(min)">
                        <el-input v-model="formLabelAlign.Min"></el-input>
                    </el-form-item>
                    <el-form-item label="数据上传间隔(sec)">
                        <el-input v-model="formLabelAlign.SEC"></el-input>
                    </el-form-item>
                    <el-form-item label="噪声上限值">
                        <el-input v-model="formLabelAlign.noise"></el-input>
                    </el-form-item>
                    <el-form-item label="IMEI值">
                        <el-input v-model="formLabelAlign.IMEI"></el-input>
                    </el-form-item>
                    <el-form-item label="ICCID值">
                        <el-input v-model="formLabelAlign.ICCID"></el-input>
                    </el-form-item>
                    <el-form-item label="目标服务器地址">
                        <el-input v-model="formLabelAlign.serveraddress"></el-input>
                    </el-form-item>

                    <el-form-item label="目标服务器端口">
                        <el-input v-model="formLabelAlign.serverport"></el-input>
                    </el-form-item>
                    <el-form-item label="终端地址(BCD码显示)">
                        <el-input v-model="formLabelAlign.BCD"></el-input>
                    </el-form-item>
                    <el-form-item label="APN接入点">
                        <el-input v-model="formLabelAlign.AccessPoint"></el-input>
                    </el-form-item>
                    <el-form-item label="APN用户名">
                        <el-input v-model="formLabelAlign.APNUser"></el-input>
                    </el-form-item>
                    <el-form-item label="APN密码">
                        <el-input v-model="formLabelAlign.APNPassword"></el-input>
                    </el-form-item>
                    <el-form-item label="MN码">
                        <el-input v-model="formLabelAlign.MN"></el-input>
                    </el-form-item>
                    <el-form-item label="PK码">
                        <el-input v-model="formLabelAlign.PK"></el-input>
                    </el-form-item>
                    <el-form-item label="Token问询间隔 分钟">
                        <el-input v-model="formLabelAlign.token"></el-input>
                    </el-form-item>
                    <el-form-item label="经度">
                        <el-input v-model="formLabelAlign.longitude"></el-input>
                    </el-form-item>
                    <el-form-item label="纬度">
                        <el-input v-model="formLabelAlign.latitude"></el-input>
                    </el-form-item>

                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
import { call, download } from '../../../api/system/device';
export default {
    props: {
        ID: Number,//这是从设备管理传入得ID
        MapID: Number//这是从首页地图传入得ID
    },
    data() {
        return {
            loading: false,
            labelPosition: 'left',
            formLabelAlign: {
                latitude: "",//纬度
                longitude: "",//经度
                token: '',//token
                PK: "",
                MN: "",
                APNPassword: "",
                APNUser: "",
                AccessPoint: "",//APN接入点
                BCD: "",
                serverport: "",//服务器端口
                serveraddress: "",//服务器地址
                ICCID: "",
                IMEI: "",
                noise: "",//噪声
                SEC: "",
                Min: "",
                Max: "",
                returndifference: "",//回差
                firing: "",//启动
                TSP: "",
                LED: ""
            }
        };
    },
    methods: {
        async read() {
            this.loading = true
            try {
                const parameter = await call({ deviceId: this.ID ? this.ID : this.MapID });
                this.loading = false
            } catch (error) {
                console.log(error, '召唤参数失败')
                this.loading = false
                this.$message({
                    showClose: true,
                    message: '召唤参数失败!',
                    type: 'success'
                });
            }
        },
        async download() {
            try {
                console.log(this.formLabelAlign)
                const DLD = await download({ deviceId: this.ID ? this.ID : this.MapID, paramIds: this.formLabelAlign })
                console.log(DLD)
            } catch (error) {
                console.log(error, '下载参数失败')
            }
        }
    }
}
</script>

<style scoped lang="scss">
.el-row {
    margin-left: 20px;

}
</style>